// 这里面就是关于急速问诊的pinia信息
import { defineStore } from 'pinia'
import type { ConsultType, FastType } from '@/enums/index.ts'
import { ref } from 'vue'

// 写pinia的时候，尽量安装组合式api的那种风格，函数名称用 use+ xxx 开头
export const useConsult = defineStore(
  'consult',
  () => {
    // 这个pinia文件，最后是帮我们准备 提交生成订单的请求的 所有参数
    const consult = ref<any>({})

    // 1. 就诊类型1找医生 2极速问诊 3开药问诊
    // ConsultType 这个类型 等价于 1|2|3
    const setType = (value: ConsultType) => {
      consult.value.type = value
    }

    // 2. 三甲医院还是普通医院，就要写一个actions
    const setIllnessType = (value: FastType) => {
      consult.value.illnessType = value
    }

    // 3. 设置当前患者看病的科室
    const setDepId = (id: string) => {
      consult.value.depId = id
    }

    // 4. 就诊信息的保存
    const setIllness = (obj: any) => {
      consult.value.illnessDesc = obj.illnessDesc
      consult.value.illnessTime = obj.illnessTime
      consult.value.consultFlag = obj.consultFlag
      consult.value.pictures = obj.pictures
    }
    const clearIllness = () => {
      delete consult.value.illnessDesc
      delete consult.value.illnessTime
      delete consult.value.consultFlag
      delete consult.value.pictures
    }

    // 5. 患者id的保存
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }

    return { consult, setType, setIllnessType, setDepId, setIllness, clearIllness, setPatientId }
  },
  {
    persist: true // 自动帮我们用localStorage进行本地储存
  }
)
